package com.yc.jpyy.mobile.controller;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.config.Config;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.mobile.service.BizService;
@Controller
@RequestMapping(value = "/student")
public class CurriculumEvaluationController extends BaseController {

	@Autowired
	private BizService bizService;
	
	private static Logger logger = LoggerFactory.getLogger(CurriculumEvaluationController.class);

	/*
	 * 课程评价接口
	 * 参数  预约记录编号(Id),车辆车况(VehicleLevel),
	 * 教练服务(EvalClass),课程质量(CourseLevel),
	 * 评价内容(EvalContent)
	 * 
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/courseEvaluate", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String courseEvaluate(HttpServletRequest request) throws UnsupportedEncodingException {
		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		try {
			String	Id = request.getParameter("appointmentId");
			String  vehicleLevel = request.getParameter("vehicleLevel");
			String  evalClass = request.getParameter("evalClass");
			String  courseLevel = request.getParameter("courseLevel");
			String  evalContent = request.getParameter("evalContent");
			if((null != Id && !Id.isEmpty())
					&& (null != vehicleLevel && !vehicleLevel.isEmpty())
					&&(null != evalClass && !evalClass.isEmpty())
					&&(null != courseLevel && !courseLevel.isEmpty())
					&&(null != evalContent && !evalContent.isEmpty())){	
				paramsMap.put("Id", Id);
				paramsMap.put("VehicleLevel", vehicleLevel);
				paramsMap.put("EvalClass", evalClass);
				paramsMap.put("CourseLevel", courseLevel);
				paramsMap.put("EvalContent", evalContent);
				response = bizService.CurriculumEvaluation(paramsMap,response);
			}else{
				response.setErrorcode(1);
				response.setMessage("缺少必填参数！");	
			}
		} catch (Exception e) {
			logger.info("CurriculumEvaluation:" + e.toString());
			response.setErrorcode(1);
			response.setMessage("评价失败！");
		}finally {	
			return  response.toJSON();
		}
	}
	
	/*
	 * 获取课程评价接口
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getCourseEvaluate", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String getCourseEvaluate(HttpServletRequest request) throws UnsupportedEncodingException {
		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		try {
			//课程ID
			String	courseId = request.getParameter("courseId");
			if(null != courseId && !courseId.isEmpty()){	
				paramsMap.put("courseId", courseId);
				paramsMap.put("imgUrl", Config.getImageAddress());
				response = bizService.getCourseEvaluate(paramsMap,response);
			}else{
				response.setErrorcode(1);
				response.setMessage("缺少必填参数！");	
			}
		} catch (Exception e) {
			logger.info("getCourseEvaluate:" + e.toString());
			response.setErrorcode(1);
			response.setMessage("获取评价失败！");
		}finally {	
			return  response.toJSON();
		}
		
	}
}
